<extend name="public@base5"/>
<block name="main">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link" href="{:url('Store/booth',['bid'=>$booth.booth_type])}">展位管理</a>
            </li>
            <li class="nav-item">
                <a class="nav-link active" href="">商品管理</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="{:url('Store/add',['type'=>$type])}">添加商品</a>
            </li>
            
        </ul>
        <div class="card margin-top-20">
            <div class="card-body">
                <form class=" bg-white row row-cols-lg-auto gap-1 g-3 align-items-center" method="get"
                      action="{:url('subindex',['type'=>$type])}">
                    <div class="col-12">
                        <input type="text" class="form-control" name="search"
                               value="{:input('request.search/s','')}" placeholder="编号/名称">
                    </div>
                    <div class="col-12">
                        <select name="item_status" class="form-control" id="status">
                            <option value="4">状态</option>
                            <option value="4">全部</option>
                            <option value="1">已上架</option>
                            <option value="2">待上架</option>
                            <option value="3">下架</option>
                        </select>
                    </div>
                    <div class="col-12">
                        <select name="key" class="form-control" id="status">
                            <option value="all">商品类型</option>
                            {$options}
                        </select>
                    </div>
                    <div class="col-12">
                        <input type="submit" class="btn btn-primary" value="{:lang('Search')}"/>
                        <a class="btn btn-danger" href="{:url('subindex',['type'=>$type])}">{:lang('Clear')}</a>
                    </div>
                </form>
            </div>
        </div>
        <table class="table table-hover table-bordered margin-top-20">
            <thead>
            <tr>
                <th width="50">编号</th>
                <th>商品名称</th>
                <th>商品类型</th>
                <th>价格</th>
                <th>库存</th>  
                <th>浏览量</th>
                <th>销售量</th>
                <th>排序</th>
                <th>图标</th>
                <th>修改时间</th>

                <th>{:lang('STATUS')}</th>
                <th width="120">{:lang('ACTIONS')}</th>
            </tr>
            </thead>
            <tbody>
            <php>
                $user_statuses=['0'=>'待上架',1=>'上架',2=>'待上架',3=>'下架'];
            </php>
            <foreach name="items" item="vo">
                <tr>
                    <td>{$vo.id}</td>
                    <td>
                        {$vo.item_name}
                    </td>
                    <td>{$vo.item_type}</td>
                   
                    <td>{$vo.item_price}</td>
                    <td>
                        {$vo.item_num} 
                    </td>
                    <td>{$vo.view_count}</td>

                    <td>{$vo.sell_count}</td>

                    <td><a class='btn btn-xs btn-info' onclick='inputOrder("{$vo.id}")' href='#'>{$vo.item_order}</a></td>
                    <td>
                        <img src="{:cmf_get_image_preview_url($vo['item_icon'])}" width="120px" height="100px">
                     </td>
                     <td>
                        {:date('Y-m-d H:i:s',$vo['update_time'])}
                    </td>
                    <td>
                        
                        <switch name="vo.item_status">
                            <case value="3">
                                <span class="badge text-bg-danger">{$user_statuses[$vo['item_status']]}</span>
                            </case>
                             <case value="2">
                                <span class="badge text-bg-danger">{$user_statuses[$vo['item_status']]}</span>
                            </case>
                            <case value="1">
                                <span class="badge text-bg-success">{$user_statuses[$vo['item_status']]}</span>
                            </case>
                        </switch>
                    </td>
                    <td>
                        
                        <if condition="$vo['item_status'] eq 1">
                            <a class="btn btn-xs btn-warning js-ajax-dialog-btn"
                               href="javascript:"
                               data-href="admin/stores/{$vo.id}/status/3"
                               data-msg="是否下架"
                               title="下架" data-toggle="tooltip">
                                <i class="fa fa-toggle-off fa-fw"></i>
                            </a>
                            <else/>
                            <a class="btn btn-xs btn-success js-ajax-dialog-btn"
                               href="javascript:"
                               data-href="admin/stores/{$vo.id}/status/1"
                               data-msg="是否上架"
                               title="上架" data-toggle="tooltip">
                                <i class="fa fa-toggle-on fa-fw"></i>
                            </a>
                        </if>
                        <a class="btn btn-xs btn-primary" href='{:url("store/edit",array("id"=>$vo["id"]))}'
                           title="{:lang('EDIT')}" data-toggle="tooltip">
                            <i class="fa fa-edit fa-fw"></i>
                        </a>
                        
                    <if condition="$vo['booth_type'] neq 1">
                        <a class="btn btn-xs btn-primary" href='{:url("store/attr",array("id"=>$vo["id"]))}'
                           title="价格、库存" data-toggle="tooltip">
                            <i class="fa fa-tags fa-fw"></i>
                        </a>
                        <a class="btn btn-xs btn-warning" href='{:url("store/property",array("id"=>$vo["id"]))}'
                           title="参数" data-toggle="tooltip">
                            <i class="fa fa-bars-staggered fa-fw"></i>
                        </a>
                    </if>
                        <a class="btn btn-xs btn-outline-primary" href="">刷新库存</a>
                        <a class="btn btn-xs btn-danger js-ajax-delete"
                           href="javascript:"
                           data-href="admin/stores/{$vo.id}" title="{:lang('DELETE')}" data-toggle="tooltip">
                            <i class="fa fa-trash fa-fw"></i>
                        </a>
                    </td>
                </tr>
            </foreach>
            </tbody>
        </table>
        <div class="pagination">{$page}</div>
    </div>
    <script>
        function  inputOrder(id){
            var order = prompt("输入排序");
            if(order.length<1){
                return;
            }
            var num = parseInt(order,10);
            if(isNaN(num)){
                return;
            }
            $.post("{:url('set_order')}",{id:id,order:num},function(d){
                location.reload();
            });
            return false;
        }
    </script>
</block>
